/*
https://leetcode.cn/problems/n-ary-tree-postorder-traversal/
590. N 叉树的后序遍历
*/
/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
public:
    vector<int> postorder(Node* root) {
       vector<int>res;
        cal(root,res);
        return res;
    }
    void cal(Node* root,vector<int>& res){
        if(root==NULL) return ;
        for(auto i: root->children){
            if(i!=NULL) cal(i,res);
        }
        res.push_back(root->val);
    }
};